<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.lang.Exception" %>
<%@ page import="com.ykzhujiang.lovespirit.util.PMF" %>
<%@ page import="com.ykzhujiang.lovespirit.util.Utility" %>
<%@ page import="com.ykzhujiang.lovespirit.util.DataManager" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.sql.Timestamp" %>
<%@ page import="javax.cache.Cache" %>
<%@ page import="javax.cache.CacheException" %>
<%@ page import="javax.cache.CacheFactory" %>
<%@ page import="javax.cache.CacheManager" %>
<%@ page import="com.google.appengine.api.memcache.stdimpl.GCacheFactory" %>
<%@ page import="com.ykzhujiang.lovespirit.entity.Notice" %>
<%@ page import="com.ykzhujiang.lovespirit.entity.LSUser" %>
<%@ page import="com.ykzhujiang.lovespirit.entity.Comment" %>
<%@ page import="com.ykzhujiang.lovespirit.analyzer.Analyzer" %>
<%@ page import="com.ykzhujiang.lovespirit.analyzer.FemaleAnalyzer" %>
<%@ page import="com.ykzhujiang.lovespirit.analyzer.MaleAnalyzer" %>
<%@ page import="com.ykzhujiang.lovespirit.entity.LThread" %>
<%@ page import="java.util.logging.Logger" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>

<link href="css/main.css" type="text/css" rel="stylesheet"></link>
<script type="text/javascript" language="JavaScript">
function change(id,id2){
      if(document.getElementById(id).style.display != "block"){
      	document.getElementById(id).style.display="block";
      	document.getElementById(id2).src="images/minus.png";
      }
      else {
      	document.getElementById(id).style.display="none";
		document.getElementById(id2).src="images/plus.png";
      }
}
</script>
<script src="http://www.google.com/jsapi"></script>
<script>
   
    google.setOnLoadCallback(function(){$(document).ready(pageLoad);});
    google.load("jquery","1.3.2");
    google.load("jqueryui","1.7");
   
    function pageLoad()
    {    
<%
		Logger logger = Logger.getLogger("index.jsp");
		int NOTICE_NUM_PERPAGE = 15;
		long TIME_INTERVAL = 7*24*3600000L;
		int MIN_HOT = 5;
		int start;
		int end;
		int type;
		try {
			start = Integer.parseInt(request.getParameter("s"));
		} catch (NumberFormatException e) {
			start = 0;
		}
		try {
			type = Integer.parseInt(request.getParameter("t"));
		} catch (NumberFormatException e) {
			type = 0;
		}
		if(type < 0 || type > 1)
			type = 0;
		end = start + NOTICE_NUM_PERPAGE;
		List<Notice> results = null;
		long begin=(new Date().getTime()-TIME_INTERVAL)*1000;
    	String query;
    	Notice notice = null;
    	if(type == 0)
    		query = "select from " + Notice.class.getName() + 
    			" where date > " + begin + " order by date desc, hot desc range " + start + "," + end;
    	else
    		query = "select from " + Notice.class.getName() + 
    			" where hot > " + MIN_HOT + " order by hot desc, date desc range " + start + "," + end;
    	results = (List<Notice>)DataManager.getData(query, false, null);
    	for(int i=0;results!=null&&i<results.size();i++){
    		notice = results.get(i);
%>
		$('#notice_<%=notice.getSourceUrl().hashCode()%>').load('thread.jsp?k=<%=Utility.EncodeUrl(notice.getSourceUrl())%>&r='+Math.random());
<%
		}
%>          
    }

</script>    
<html>
  <head>
    <link rel="shortcut icon" href="images/logo.ico">
    <link rel="Bookmark" href="images/favicon.ico">
    <title>
 	  lovespirit
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
  </head>
  <body>

<%@ include file='usrbar.jsp' %>

<div id="main">
<ol id="mainol">
<div id="stype">
<%
	if(type == 0) {
%>
	<span class="selected">New</span>
	<a class="toselect" href="/?t=1">Hot</a>
<%
	}
	else if(type == 1) {
%>
	<a class="toselect" href="/?t=0">New</a>
	<span class="selected">Hot</span>
<%
	}
%>
<span class="todo">Post</span>
</div>
<%
	for(int i=0;results!=null&&i<results.size();i++){
%>
<div id="notice_<%=((Notice)results.get(i)).getSourceUrl().hashCode()%>" class="notice">
</div>
<%
	}
%>
<div id="pages">
<%
	if(results != null && start > 0) {
%>
	<a class="prev" href="/?s=<%=Math.max(start-NOTICE_NUM_PERPAGE,0)%>&t=<%=type%>">
		上一页
	</a>
<%
	}
%>
<%
	if(results != null && results.size() != 0) {
%>
	<a class="next" href="/?s=<%=start+NOTICE_NUM_PERPAGE%>&t=<%=type%>">
		下一页
	</a>
<%
	}
%>
</div>
</ol>
</div>
<div class="footer">
©2009 Love Spirit 
<a href="/about.jsp">About Me</a>
</div>
  </body>
</html>
